package com.titan.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: Customer
 *
 */
@Entity
@Table(name="CUSTOMER")
@NamedQuery(name="testQuery", 
		query="SELECT c.ssn FROM Customer AS c WHERE LENGTH(c.lastName) > 4")
@IdClass(CustomerPK.class)
public class Customer implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private String firstName;
	private String lastName;
	private long ssn;
	private CustomerType customerType;
	private Address address;
	private CreditCard creditCard;
	private Collection<Reservation> reservations=new ArrayList<Reservation>();
	
	@ManyToMany(mappedBy="customers")
	public Collection<Reservation> getReservations() {
		return reservations;
	}
	public void setReservation(Collection<Reservation> reservations) {
		this.reservations = reservations;
	}
	
	@OneToOne(cascade={CascadeType.ALL})
	@JoinColumn(name="CREDIT_CARD_ID")	
	public CreditCard getCreditCard() {
		return creditCard;
	}
	public void setCreditCard(CreditCard creditCard) {
		this.creditCard = creditCard;
	}
	@Id
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Id
	public long getSsn() {
		return ssn;
	}
	public void setSsn(long ssn) {
		this.ssn = ssn;
	}

	@Enumerated(EnumType.ORDINAL)
	public CustomerType getCustomerType() {
		return customerType;
	}
	public void setCustomerType(CustomerType customerType) {
		this.customerType = customerType;
	}
	
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="Address_id")
	public Address getAddress() {
		return address;
	}
	public void setAddress(Address address) {
		this.address = address;
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
}
